home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Talker / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-09  |  5.8 KB  |  217 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWCLPCMD_H
  31. #include "FWClpCmd.h"            // FW_CClipboardCommand
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35. #ifndef FWCFMRES_H
  36. #include "FWCFMRes.h"            // FW_PSharedLibraryResourceFile
  37. #endif
  38.  
  39. #ifndef FWMENU_H
  40. #include "FWMenu.h"                // FW_CMenuBar, etc.
  41. #endif
  42.  
  43. #ifndef FWEVENT_H
  44. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  45. #endif
  46.  
  47. #ifndef FWRECSHP_H
  48. #include "FWRecShp.h"            // FW_CRectShape
  49. #endif
  50.  
  51. #ifndef FWPICSHP_H
  52. #include "FWPicShp.h"            // FW_CPicture, FW_CPictureShape
  53. #endif
  54.  
  55. #ifndef FWRRCSHP_H
  56. #include "FWRRcShp.h"            // FW_CRoundRectShape
  57. #endif
  58.  
  59. #ifndef FWDRCMD_H
  60. #include "FWDrCmd.h"            // FW_CDropCommand
  61. #endif
  62.  
  63. // ----- OpenDoc Includes -----
  64. #ifndef SOM_ODDragItemIterator_xh
  65. #include <DgItmIt.xh>            // ODDragItemIterator
  66. #endif
  67.  
  68. #ifndef SOM_ODTranslation_xh    
  69. #include <Translt.xh>            // ODTranslation    
  70. #endif
  71.  
  72. #ifndef SOM_Module_OpenDoc_StdProps_defined
  73. #include <StdProps.xh>            // kODPropContents
  74. #endif
  75.  
  76. //========================================================================================
  77. #ifdef FW_BUILD_MAC
  78. #pragma segment Talker
  79. #endif
  80.  
  81. FW_DEFINE_AUTO(CTalkerFrame)
  82.  
  83. //========================================================================================
  84. CTalkerFrame::CTalkerFrame(Environment* ev, ODFrame* odFrame, 
  85.                             FW_CPresentation* presentation, CTalkerContent* content)
  86.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  87.     FW_MDroppableFrame(ev, this),    
  88.     fTalkerContent(content),
  89.     fPictShape(NULL)
  90. {
  91.     this->MyInitPicture(ev);
  92.     FW_END_CONSTRUCTOR
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. void
  97. CTalkerFrame::MyInitPicture(Environment* ev)
  98. {
  99.     FW_PSharedLibraryResourceFile resFile(ev);            // PICT resource in shared library
  100.     const short kPizzaPictID = 2000;
  101.     FW_CPicture picture(resFile, kPizzaPictID);
  102.     fFrameRect = this->GetBounds(ev);        // Get new Frame Rect
  103.     fPictShape = FW_NEW(FW_CPictureShape, (picture, fFrameRect));
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. CTalkerFrame::~CTalkerFrame()
  108. {
  109.     FW_START_DESTRUCTOR
  110.     delete fPictShape;
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. void 
  115. CTalkerFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  116. {
  117.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  118.     
  119.     // erse invalid shape
  120.     FW_CRect invalidRect;
  121.     context.GetClipRect(invalidRect);
  122.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  123.     // draw the picture
  124.     fPictShape->Render(context);
  125.     // draw a frame around it
  126.     FW_CRoundRectShape::RenderRoundRect(context,
  127.                                         fFrameRect, 
  128.                                         FW_CPoint(FW_IntToFixed(30), FW_IntToFixed(30)),
  129.                                         FW_kFrame,
  130.                                         FW_CInk(FW_kRGBBlue));
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. void 
  135. CTalkerFrame::FrameShapeChanged(Environment* ev)
  136. {
  137.     FW_CFrame::FrameShapeChanged(ev);
  138.     fFrameRect = this->GetBounds(ev);    // Get new frame rect
  139.     // modify picture
  140.     FW_CPicture picture = fPictShape->GetPicture();
  141.     fPictShape->SetGeometry(picture, fFrameRect);
  142.     // force redraw of whole frame
  143.     this->Invalidate(ev, fFrameRect);            
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. FW_Handled 
  148. CTalkerFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  149.                             FW_Boolean isRoot)    // Override
  150. {
  151.     FW_UNUSED(isRoot);
  152.     if (hasMenuFocus) {
  153.         FW_Boolean hasRightProperty = FALSE;
  154.         menuBar->EnableCommand(ev, kODCommandPaste, HasSupportedKindOnClipboard(ev));
  155.         menuBar->EnableCommand(ev, cFasterCmd, TRUE);
  156.         menuBar->EnableCommand(ev, cSlowerCmd, TRUE);
  157.     }
  158.     return FALSE;
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. FW_Handled 
  163. CTalkerFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  164. {
  165.     FW_Handled menuHandled = TRUE;
  166.     CTalkerCommand* cmd = NULL;
  167.     switch (theMenuEvent.GetCommandID(ev)) { 
  168.         case cFasterCmd:         
  169.             cmd = FW_NEW(CTalkerCommand, (ev, cFasterCmd, this, 
  170.                                             fTalkerContent->MyGetTalker()));
  171.             cmd->Execute(ev);
  172.             break;
  173.         
  174.         case cSlowerCmd: 
  175.             cmd = FW_NEW(CTalkerCommand, (ev, cSlowerCmd, this, 
  176.                                             fTalkerContent->MyGetTalker()));
  177.             cmd->Execute(ev);
  178.             break;
  179.  
  180.         default:
  181.             menuHandled = FALSE;
  182.     }
  183.     return menuHandled;
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. FW_Handled 
  188. CTalkerFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  189. {    
  190.     FW_Handled handledEvent = FALSE;
  191.     if (theMouseEvent.GetNumberOfClicks(ev) == 2) {
  192.         fTalkerContent->MySayText(ev);
  193.         handledEvent = TRUE;
  194.         }
  195.     return handledEvent;
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. FW_CDropCommand* 
  200. CTalkerFrame::NewDropCommand(Environment *ev, 
  201.                                     FW_CFrame* frame,
  202.                                     ODDragItemIterator* dropInfo, 
  203.                                     ODFacet* facet, 
  204.                                     const FW_CPoint& dropPoint)
  205. {
  206.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, !FW_kCanUndo) );
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. FW_CClipboardCommand* 
  211. CTalkerFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  212. {
  213.     return FW_NEW(FW_CClipboardCommand, 
  214.             (ev, commandID, this, ! FW_kCanUndo) );
  215. }
  216.  
  217.